//
//  UIButton+Extension.swift
//  01_新浪微博
//
//  Created by 黄蓉 on 15/12/17.
//  Copyright © 2015年 黄蓉. All rights reserved.
//

import UIKit


extension UIButton {
    ///  UIButton 的便利构造方法
    ///  * title                title
    ///  * normalImageName      普通状态下的按钮背景图片
    ///  * highlightedImageName 高亮状态下的按钮背景图片
    ///  * action               触发的方法
    ///  * color                文字颜色
    convenience init(title: String, normalImageName: String,  color: UIColor, target: AnyObject,action: Selector) {
        self.init()
       setBackgroundImage(UIImage(named: normalImageName), forState: .Normal)
       setBackgroundImage(UIImage(named:normalImageName + "__highlighted"), forState: .Highlighted)
       setTitle(title, forState: .Normal)
       setTitleColor(color, forState: .Normal)
       sizeToFit()
       addTarget(target, action: action, forControlEvents: .TouchUpInside)
    
    }
    ///  UIButton的便利构造方法(设置图片)
    ///  * normalImageName 按钮图片(普通和高亮)
    ///  * backImageName   按钮背景图片(普通和高亮)
    convenience init(normalImageName: String, backImageName: String) {
        self.init()
        setImage(UIImage(named: normalImageName), forState: .Normal)
        setImage(UIImage(named: normalImageName + "_highlighted"), forState: .Highlighted)
        //设置背景图片
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        
    }
    
}